package com.example.xgakj.mvp_demo.ui.activities.login;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xgakj.mvp_demo.MainActivity;
import com.example.xgakj.mvp_demo.R;
import com.example.xgakj.mvp_demo.mvp.MVPBaseActivity;
import com.example.xgakj.mvp_demo.ui.activities.RegisterActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LoginActivity extends MVPBaseActivity<LoginContract.View, LoginPresenter> implements LoginContract.View {
    @BindView(R.id.image_left)
    ImageView imageLeft;
    @BindView(R.id.tv_set)
    TextView tvSet;
    @BindView(R.id.ed_name)
    EditText edName;
    @BindView(R.id.ed_password)
    EditText edPassword;
    @BindView(R.id.btn_login)
    Button btnLogin;
    private String user;
    private String passWord;
    private ProgressDialog mDialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        mDialog=new ProgressDialog(this);
        mDialog.setMessage("正在登录。。");
        mDialog.setCanceledOnTouchOutside(false);
    }

    @OnClick({R.id.image_left, R.id.tv_set, R.id.btn_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.image_left:

                break;
            case R.id.tv_set:
                Intent intent=new Intent(this, RegisterActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_login:
                user=edName.getText().toString().trim();
                passWord=edPassword.getText().toString().trim();
                mPresenter.login(user,passWord);
                break;
        }
    }

    @Override
    public void showDialog() {
        mDialog.show();
    }

    @Override
    public void dismissDialog() {
        mDialog.dismiss();
    }

    @Override
    public void enterMain() {
        Intent intent=new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}
